package extra;

public class AlgoritimoBackoff {

	private static final double SLOT_TEMPO        = 0.0512;
	private static final int    COLISOES_MAXIMO   = 10;
	private static final int    COLISOES_DESCARTE = 16;

	public static double geraAtraso(int numeroColisoes)
	{
		if (numeroColisoes >= COLISOES_DESCARTE)
		{
			return -1;
		}
		else
		{
			int k = Math.min(numeroColisoes, COLISOES_MAXIMO);
			double tempo = (int) (Gerador.geraNumeroReal() * (Math.pow(2, k))) * (SLOT_TEMPO);
			return Math.floor(tempo * 10000)/10000;
		}
	}

}